package com.digitalchina.lxnsy.activity.old;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.apkfuns.logutils.LogUtils;
import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessEvaluate;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：白彦东
 * 创建时间：2017/1/20 15:07
 * 修改备注：
 * ================================================
 */

public class AdditionalEvaluationActivity extends BaseActivity {
    @Bind(R.id.add_evaluation_iv_images)
    SimpleDraweeView addEvaluationIvImages;
    @Bind(R.id.product_iv_star1)
    ImageView productIvStar1;
    @Bind(R.id.product_iv_star2)
    ImageView productIvStar2;
    @Bind(R.id.product_iv_star3)
    ImageView productIvStar3;
    @Bind(R.id.product_iv_star4)
    ImageView productIvStar4;
    @Bind(R.id.product_iv_star5)
    ImageView productIvStar5;
    @Bind(R.id.item_evaluate_product_content)
    TextView itemEvaluateProductContent;
    @Bind(R.id.add_evaluation_product_content)
    EditText addEvaluationProductContent;
    @Bind(R.id.additional_evaluation_button)
    TextView additionalEvaluationButton;

    private Map<String, Object> dataMap = new HashMap<>();
    private String productImg; // 商品图片
    private String evaluateProductId; // 评价ID
    private String evaluateContent; // 评价内容
    private int evaluateScore; // 评价分数

    @Override
    public void setLayout() {
        setTitle("追加评价");
        setContentLayout(R.layout.activity_additional_evaluation);
    }

    @Override
    public void initMember() {
        if (getIntent().hasExtra("data")) {
            dataMap = (Map<String, Object>) getIntent().getSerializableExtra("data");
            LogUtils.e(dataMap);
            evaluateProductId = (String) dataMap.get("evaluateProductId");
            productImg = (String) dataMap.get("productImg");
            evaluateContent = (String) dataMap.get("evaluateContent");
            evaluateScore = (Integer) dataMap.get("evaluateScore");
            initContent();
        }
    }

    private void initContent() {
        FrescoUtil.showImageSmall(productImg, addEvaluationIvImages);//商品图片
        setProductStar(evaluateScore);
        itemEvaluateProductContent.setText(evaluateContent);
    }

    /**
     * 设置商品评论星数
     *
     * @param score
     */
    private void setProductStar(int score) {
        switch (score) {
            case 1:
                productIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar2.setImageResource(R.drawable.icon_average_star_hollow);
                productIvStar3.setImageResource(R.drawable.icon_average_star_hollow);
                productIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                productIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case 2:
                productIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar3.setImageResource(R.drawable.icon_average_star_hollow);
                productIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                productIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case 3:
                productIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                productIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case 4:
                productIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar4.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case 5:
                productIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar4.setImageResource(R.drawable.icon_average_star_solid);
                productIvStar5.setImageResource(R.drawable.icon_average_star_solid);
                break;
        }
    }

    @Override
    public void addListener() {
        additionalEvaluationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (StringUtil.isStrEmpty(StringUtil.getEditText(addEvaluationProductContent))) {
                    showToast("请填写追加内容");
                    return;
                }
                BusinessEvaluate.addAdditionEvaContent(AdditionalEvaluationActivity.this, evaluateProductId,
                        StringUtil.getEditText(addEvaluationProductContent), mHandler);
            }
        });
    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG.MSG_ADD_ADDITION_EVA_CONTENT_SUCCESS:
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_ADD_ADDITION_EVA_CONTENT_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    @Override
    public void callBack(Object object) {
        showToast("评价成功");
        GotoUtil.gotoActivity(AdditionalEvaluationActivity.this, OrderListActivity.class, true);
    }

    @Override
    public void rightOnClick() {

    }

}
